import re

from django.test import TestCase

from common.utils import gen_mobile_code, to_md5_hex


class UtilTest(TestCase):

    def setUp(self):
        self.pattern = re.compile(r'\d{6}')

    def test_gen_mobile_code(self):
        for _ in range(100):
            self.assertIsNotNone(self.pattern.match(gen_mobile_code()))

    def test_to_md5_hex(self):
        md5_dict = {
            '123456': 'e10adc3949ba59abbe56e057f20f883e',
            '123123123': 'f5bb0c8de146c67b44babbf4e6584cc0',
            '1qaz2wsx': '1c63129ae9db9c60c3e8aa94d3e00495',
        }
        for key, value in md5_dict.items():
            self.assertEqual(value, to_md5_hex(key))


"""
class ModelTest(TestCase):

    def test_save_province(self):
        pass
        # prov = Province(prov_name='湖南省')
        # prov.save()
        # self.assertIsNotNone(prov.prov_id)

    def test_del_province(self):
        pass

    def test_update_province(self):
        pass

    def test_get_all_provinces(self):
        pass

    def test_get_province_by_id(self):
        pass
"""
